{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "according-ordinance",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "defined \u001b[32mobject\u001b[39m \u001b[36mD\u001b[39m"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "object D extends App {\n",
    "    @deprecated(\"deprecation message\",\"release # which deprecates method\")\n",
    "    def hello = \"hello\"\n",
    "    \n",
    "    hello\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "olive-poetry",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "defined \u001b[32mfunction\u001b[39m \u001b[36mhello\u001b[39m"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    " @deprecated(\"deprecation message\", \"release # which deprecates method\")\n",
    "  def hello = \"hola\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "charitable-sample",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\u001b[32mimport \u001b[39m\u001b[36mscala.annotation.tailrec\n",
       "\n",
       "\u001b[39m\r\n",
       "defined \u001b[32mfunction\u001b[39m \u001b[36mfactorial\u001b[39m"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import scala.annotation.tailrec\n",
    "\n",
    "def factorial(x:Int):Int = {\n",
    "    \n",
    "    @tailrec\n",
    "    def factorialHelper(x:Int,acc: Int):Int = {\n",
    "        if (x==1) acc else factorialHelper(x-1,x*acc )//没有东西了，尾递归\n",
    "    }\n",
    "    \n",
    "    factorialHelper(x,1)\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "strategic-massachusetts",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "(console):4:17 expected (If | While | Try | DoWhile | For | Throw | Return | ImplicitLambda | SmallerExprOrLambda)\r\n",
      "def factorial(x: Int): Int = {\n",
      "  @tailrec\n",
      "  def factorialHelper(x: Int): Int = {\n",
      "    if (x == 1) else   x*factorialHelper(x - 1)//非尾递归，因为还有x*。下一个函数结束以后此函数还有后续，所以必须保存本身的环境以供处理返回值。\n",
      "  }\n",
      "  factorialHelper(x)\n",
      "}\r\n",
      "                                                                                                 ^"
     ]
    },
    {
     "ename": "",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "(console):4:17 expected (If | While | Try | DoWhile | For | Throw | Return | ImplicitLambda | SmallerExprOrLambda)\r\ndef factorial(x: Int): Int = {\n  @tailrec\n  def factorialHelper(x: Int): Int = {\n    if (x == 1) else   x*factorialHelper(x - 1)//非尾递归，因为还有x*。下一个函数结束以后此函数还有后续，所以必须保存本身的环境以供处理返回值。\n  }\n  factorialHelper(x)\n}\r\n                                                                                                 ^"
     ]
    }
   ],
   "source": [
    "def factorial(x: Int): Int = {\n",
    "  @tailrec\n",
    "  def factorialHelper(x: Int): Int = {\n",
    "    if (x == 1) else   x*factorialHelper(x - 1)//非尾递归，因为还有x*。下一个函数结束以后此函数还有后续，所以必须保存本身的环境以供处理返回值。\n",
    "  }\n",
    "  factorialHelper(x)\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "indie-niagara",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "(console):1:12 expected (Dcl | TraitDef | ClsDef | ObjDef)\r\n",
      "@interface SourceURL {\n",
      "    public String value();\n",
      "    public String mail() default \"\";\n",
      "}\n",
      "@SourceURL(\"https://coders.com/\",\n",
      "           mail = \"support@coders.com\")\n",
      "    class MyScalaClass {\n",
      "        def x  = \"xx\"\n",
      "    }\r\n",
      "           ^"
     ]
    },
    {
     "ename": "",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "(console):1:12 expected (Dcl | TraitDef | ClsDef | ObjDef)\r\n@interface SourceURL {\n    public String value();\n    public String mail() default \"\";\n}\n@SourceURL(\"https://coders.com/\",\n           mail = \"support@coders.com\")\n    class MyScalaClass {\n        def x  = \"xx\"\n    }\r\n           ^"
     ]
    }
   ],
   "source": [
    "@interface SourceURL {\n",
    "    public String value();\n",
    "    public String mail() default \"\";\n",
    "}\n",
    "@SourceURL(\"https://coders.com/\",\n",
    "           mail = \"support@coders.com\")\n",
    "    class MyScalaClass {\n",
    "        def x  = \"xx\"\n",
    "    }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "literary-remainder",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Scala",
   "language": "scala",
   "name": "scala"
  },
  "language_info": {
   "codemirror_mode": "text/x-scala",
   "file_extension": ".scala",
   "mimetype": "text/x-scala",
   "name": "scala",
   "nbconvert_exporter": "script",
   "version": "2.11.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
